//
//  ShadowedTextView.m
//  LineByLine
//
//  Created by 병철 김 on 11. 10. 6..
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ShadowedTextView.h"


@implementation ShadowedTextView
@synthesize text, delegate;

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor clearColor]];
    }
    return self;
}

- (void)drawRect:(CGRect)rect {
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);
    
    CGContextSetShadowWithColor(context, CGSizeMake(6.0f, 6.0f), 3.0f, [UIColor colorWithRed:0.05 green:0.05 blue:0.05 alpha:1.0].CGColor);
    CGContextSetRGBFillColor (context, 0.76, 0.78, 0.79, 1);
    
    [text drawInRect:rect withFont:[UIFont systemFontOfSize:24] lineBreakMode:UILineBreakModeWordWrap];
    
    CGContextRestoreGState(context);
}

- (void) setText:(NSString *)_text {
    if (_text && _text != text) {
        [text release];
        text = [_text retain];
    }
    [self setNeedsDisplay];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    isClicking = YES;
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    isClicking = NO;
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    isClicking = NO;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if (isClicking) {
        isClicking = NO;
        [delegate onClickText:self];
    }
}
@end
